<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
    <meta name="author" content="明月">
    <title>倒计时</title>
    <style>
        div {
            width: 300px;
            height: 150px;
            background-color: #222;
            margin: 0 auto;
            color: white;
            padding: 10px;
            text-align: center;
            font-size: 20px;
        }

        input {
            display: inline-block;
            width: 60px;
            height: 30px;
            background-color: #FFF;
            border: 2px solid #999;
            color: #000;
            margin: 20px 5px;
            padding-left: 10px;
        }

        button {
            background-color: skyblue;
            font-size: 23px;
            border: none;
            border-radius: 3px;
        }
    </style>
</head>

<body>
    <div id="timer">
        <p>
            <input type="text" name="" value="2" class="minute">分
            <input type="text" name="" value="30" class="second">秒
        </p>
        <button type="text">开始倒计时</button>
    </div>
</body>

</html>
<script>
    var sec = document.querySelector('.second');
    var min = document.querySelector('.minute');
    var button = document.querySelector('button');
    var timer;
    var t1;
    var t2;

    var mn = Number(min.value);
    // console.log(mn);
    var sn = Number(sec.value);

    function second() {
            if (sn > 0 && sn < 60) {
                sn = sn - 1;
                if (sn < 10) {
                    sec.value = '0' + sn;
                } else {
                    sec.value = sn;
                }
            }
    }
    function minute() {
        if (mn > 0 && sn == 0) {
            mn = mn - 1;
            sn = 59;
            // timer = setInterval(second, 1000);
            if (mn < 10) {
                min.value = '0' + mn;
            } 
            else {
                min.value = mn;
            }
        }
    }
        // t1 = setInterval(minute, 1000);
        // t2 = setInterval(second, 1000);

    var isclick = true;
    button.onclick = function () {
        if (isclick) {
            clearInterval(t1);
            clearInterval(t2);
            button.innerHTML = '开始倒计时';
            isclick = false;
        }
         else {
            t1 = setInterval(minute, 1000);
            t2 = setInterval(second, 1000);
            button.innerHTML = '暂停倒计时';
            isclick = true;
        }
    }

</script>